package edu.grupo4.appeventos;


import java.util.Calendar;

import edu.espol.appeventos.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

import com.facebook.*;
import com.facebook.model.*;

public class EventDetails extends Activity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_event_details);
        
              
      ImageButton btnFacebook= (ImageButton) findViewById(R.id.ibFacebook);
      ImageButton btnTwitter = (ImageButton) findViewById(R.id.ibTwitter);
      ImageButton btnCalendario = (ImageButton) findViewById(R.id.ibCalendario);
      ImageButton btnMaps= (ImageButton) findViewById(R.id.ibMap);
      
      
      btnFacebook.setOnClickListener(this);


      
      btnTwitter.setOnClickListener(new OnClickListener() {		
    		@Override
    		public void onClick(View v) {
    			// TODO Auto-generated method stub
    		
    		}
        });
      
      btnCalendario.setOnClickListener(new OnClickListener() {		
    		@Override
    		public void onClick(View v) {
    			// TODO Auto-generated method stub
    			Calendar cal = Calendar.getInstance();              
    			Intent intent = new Intent(Intent.ACTION_EDIT);
    			intent.setType("vnd.android.cursor.item/event");
    			intent.putExtra("beginTime", cal.getTimeInMillis());
    			intent.putExtra("allDay", true);
    			intent.putExtra("rrule", "FREQ=YEARLY");
    			intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
    			intent.putExtra("title", "A Test Event from android app");
    			startActivity(intent); 
    		
    		}
        });
  	
      
      
      btnMaps.setOnClickListener(new OnClickListener() {		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			Intent irmap= new Intent(getApplicationContext(), MapClass.class);
			startActivity(irmap);
		}
	});
        
    }

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.getId() == R.id.ibFacebook){
			Session.openActiveSession(this, true, new Session.StatusCallback() {

			    // callback when session changes state
			    @SuppressWarnings("deprecation")
				@Override
			    public void call(Session session, SessionState state, Exception exception) {
			    	if (session.isOpened()) {
			    		// make request to the /me API
			    		Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
			    		  // callback after Graph API response with user object
			    		  @Override
			    		  public void onCompleted(final GraphUser user, final Response response) {
			    			  if (user != null) {
			    				  final TextView welcome = (TextView) findViewById(R.id.textView);
			    				  welcome.setText("Hello " + user.getName() + "!");
			    				}
			    		  }
			    		});
			    	}
			    }
			  });
		}
		
	}
    
    
    
}
